| Conditions | 3 | 
| Total Lines | 52 | 
| Code Lines | 44 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import React from 'react'; | ||
| 6 | |||
| 7 | export default function DeleteModal({navigation, modalVisible, setModalVisible, setIsLoggedIn}) { | ||
| 8 | |||
| 9 |     async function deleteAccount(navigation) { | ||
| 10 | const result = await userModel.deleteAccount(); | ||
| 11 | |||
| 12 |         if (Object.prototype.hasOwnProperty.call(result, 'errors')) { | ||
| 13 |             showMessage({ | ||
| 14 | message: result['errors']['title'], | ||
| 15 | type: 'danger' | ||
| 16 | }) | ||
| 17 | |||
| 18 | return; | ||
| 19 | }; | ||
| 20 | |||
| 21 |         showMessage({ | ||
| 22 | message: result['message'], | ||
| 23 | type: 'danger' | ||
| 24 | }); | ||
| 25 | |||
| 26 | setIsLoggedIn(false); | ||
| 27 |         navigation.navigate('Auth'); | ||
| 28 | } | ||
| 29 | |||
| 30 | return ( | ||
| 31 | <Modal | ||
| 32 | animationType='fade' | ||
| 33 |         transparent={true} | ||
| 34 |         visible={modalVisible} | ||
| 35 |         onRequestClose={() => { | ||
| 36 | setModalVisible(!modalVisible); | ||
| 37 | }} | ||
| 38 | > | ||
| 39 |             <View style={styles.modalContainer}> | ||
| 40 | |||
| 41 |                 <View style={[styles.messageContainer, styles.shadowProp]}> | ||
| 42 |                     <Text style={styles.title}>Are you sure you want to delete your account?</Text> | ||
| 43 | |||
| 44 |                     <Pressable style={[styles.prepaidButton]} onPress={() => { | ||
| 45 | deleteAccount(navigation) | ||
| 46 | }}> | ||
| 47 |                         <Text style={{color: 'white'}}>Yes, delete account</Text> | ||
| 48 | </Pressable> | ||
| 49 | |||
| 50 |                     <Pressable style={[styles.prepaidButton, {backgroundColor: 'grey'}]} onPress={() => { | ||
| 51 | setModalVisible(!modalVisible); | ||
| 52 | }}> | ||
| 53 |                         <Text style={{color: 'white'}}>No</Text> | ||
| 54 | </Pressable> | ||
| 55 | </View> | ||
| 56 | </View> | ||
| 57 | </Modal> | ||
| 58 | ) | ||
| 101 | }) |